package com.sunday.aomicaichang.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sunday.common.adapter.MainFragmentPagerAdapter;
import com.sunday.common.base.BaseActivity;
import com.sunday.common.utils.StringUtils;
import com.sunday.aomicaichang.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yun_sheng on 2017/6/2.
 */

public class MallRechangeRecordActivity extends BaseActivity {
    @Bind(R.id.tab_layout)
    TabLayout tabLayout;
    @Bind(R.id.view_pager)
    ViewPager viewPager;
    private Context mContext;
    final static int NO_ICON = 0x123;
    private List<String> titles = new ArrayList<>();
    private int[] tabIcons = {
            R.mipmap.triangle_down,
            NO_ICON
    };

    private int catId=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exchange_record);
        ButterKnife.bind(this);
        mContext = this;
        initView();

    }
    private void initView(){
        titles.add("处理中");
        titles.add("已完成");
        initFragment();
        tabLayout.getTabAt(0).setCustomView(getFirstTabView());

    }

    public View getFirstTabView(){
        View view= LayoutInflater.from(mContext).inflate(R.layout.layout_tabview,null);
        TextView txt_title = (TextView) view.findViewById(R.id.tab_title);
        txt_title.setText(titles.get(0));
        ImageView image_title = (ImageView) view.findViewById(R.id.tab_icon);
        image_title.setImageResource(R.mipmap.triangle_down);
        return view;
    }

    private ArrayList<Fragment> fragments=new ArrayList<>();
    private void initFragment(){
        List<String> str=new ArrayList<>();
        str.add("2");
        List<String> str1=new ArrayList<>();
        str1.add("3"); str1.add("4"); str1.add("5");
        fragments.add(MallRechangeRecordFragment.newInstance(StringUtils.listToString(str)));
        fragments.add(MallRechangeRecordFragment.newInstance(StringUtils.listToString(str1)));
        viewPager.setAdapter(new MainFragmentPagerAdapter(getSupportFragmentManager(),fragments,titles));
        tabLayout.setupWithViewPager(viewPager);
        viewPager.setCurrentItem(0,false);
        viewPager.setOffscreenPageLimit(2);
    }
}
